<?php
namespace App\Http\Controllers\Property;


use App\Common\json;
use App\Http\Controllers\Controller;

class CurlController extends Controller{

    public function bundle_url(){
        $data    = "http://www.mukitech.com/ddk/index.php/entry/json_wuye_chenxiang";
        $datas    = $this ->gets($data);
        $db     = json_decode($datas,true);
        $sum = count($db['data']);
        for ($i=0;$i<$sum;$i++){
            $d[] = $db['data'][$i]['bundle_url'];
        }
        return json::json('success','获取url',$d);
        }


    public function json_null($str){

        $result = str_replace(":null,",":\"\",",$str);
        $result = str_replace(":null",":\"\"",$result);
        $pos = strpos($result, "\r\n\r\n");
        $response = substr($result, $pos+4);
        return $response;
    }

    public function gets($url){
        $curl = curl_init();
    //设置抓取的url
      curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
      curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 //执行命令
         $data = curl_exec($curl);

         curl_close($curl);

       return $this->json_null($data);
    }

}